﻿
Partial Class WebForm_ManageWorkContent
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.InitData()
        End If

        Me.Form.Enctype = "multipart/form-data"
    End Sub

    Protected Sub AddWorkHeader1_Saving(ByVal sender As Object, ByVal e As System.EventArgs) Handles AddCleanPlan1.Saved
        If Me.SaveData = True Then
            '列表檢視模式
            Me.TabContainer1.ActiveTab = Me.SearchCleanPlanItemTabPanel
            Me.SearchCleanPlan1.BindGV()
            MyObj.ShowMessage(Me.GetLocalResourceObject("SaveData_Success"))
        End If
    End Sub

    Protected Sub SearchCleanPlan1_Loaded(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchCleanPlan1.Loaded
        Me.SearchCleanPlan1.BindGV()
    End Sub
    Protected Sub SearchPlanHeader1_Add(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchPlanHeader1.Add
        Me.TabContainer1.ActiveTab = Me.AddCleanPlanTabPanel
        Me.AddPlanHeader1.InitData()
    End Sub

    Protected Sub SearchPlanHeader1_Editing(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchPlanHeader1.Editing
        Me.TabContainer1.ActiveTab = Me.AddCleanPlanTabPanel
        Me.AddPlanHeader1.InitData(Me.SearchPlanHeader1.PlanHeaderID)
    End Sub

    Protected Sub AddPlanHeader1_Saved(ByVal source As Object, ByVal e As System.EventArgs) Handles AddPlanHeader1.Saved
        Me.TabContainer1.ActiveTab = Me.SearchCleanPlanTabPanel
        MyObj.ShowMessage(Me.GetLocalResourceObject("SaveData_Success"))
        Me.SearchPlanHeader1.BindGV()
    End Sub


    Protected Sub lknAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lknAdd.Click
        Me.TabContainer1.ActiveTab = Me.AddCleanPlanItemTabPanel
        Me.InitData()
    End Sub

    Protected Sub AddCleanPlan1_Saved(ByVal source As Object, ByVal e As System.EventArgs) Handles AddCleanPlan1.Saved
        Me.InitDataForSearch()
    End Sub

    Protected Sub SearchRegion1_Updating(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchCleanPlan1.Updating
        Me.InitData(FormViewMode.Edit)
    End Sub

    Protected Sub SearchCleanPlan1_Add(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchCleanPlan1.Add
        Me.TabContainer1.ActiveTab = Me.AddCleanPlanItemTabPanel
        Me.InitData()
    End Sub

    Protected Sub SearchRegion1_Deleting(ByVal sender As Object, ByVal e As System.EventArgs) Handles SearchCleanPlan1.Deleting
        Dim dat As New clsData
        Dim sql As New MyStringBuilder
        Using scope As New Transactions.TransactionScope
            sql.Length = 0
            sql.AppendFormat("Delete CleanPlan ")
            sql.AppendFormat(" where PlanID='{0}' ", Me.SearchCleanPlan1.SelectedPlanID)
            dat.AccData(sql)
            sql.Length = 0
            sql.AppendFormat("Delete CleanPlanItem ")
            sql.AppendFormat(" where PlanID='{0}' ", Me.SearchCleanPlan1.SelectedPlanID)
            dat.AccData(sql)
            scope.Complete()
        End Using
        Me.SearchCleanPlan1.BindGV()
    End Sub

    Protected Sub SearchCleanPlan1_SelectedIndexChanged(ByVal source As Object, ByVal e As System.EventArgs) Handles SearchCleanPlan1.SelectedIndexChanged
        Me.InitData(FormViewMode.ReadOnly)
    End Sub
End Class

Partial Class WebForm_ManageWorkContent
    Public Sub InitData()
        Me.AddCleanPlan1.InitData()
        Me.AddPlanHeader1.InitData()
    End Sub

    Private Sub InitDataForSearch()
        Me.TabContainer1.ActiveTab = Me.SearchCleanPlanItemTabPanel
        Me.SearchCleanPlan1.BindGV()
    End Sub

    Private Sub InitData(ByVal dataAccessMode As FormViewMode)
        Me.AddCleanPlan1.DataAccessMode = dataAccessMode
        Me.TabContainer1.ActiveTab = Me.AddCleanPlanItemTabPanel
        Me.AddCleanPlan1.InitData(Me.SearchCleanPlan1.SelectedPlanID)
    End Sub

    Private Function SaveData() As Boolean
        'Dim dat As New clsData
        'Dim sql As New MyStringBuilder

        'Using scope As New Transactions.TransactionScope
        '    If (Me.AddWorkHeader1.DataAccessMode = My.DataAccessMode.Insert) Then
        '        sql.Length = 0
        '        sql.AppendFormat("insert WorkHeader (WorkItemID,WorkName,OrganizationID,WorkPlace,Status,CreateType,CreateDate,CreateBy) select ")
        '        sql.AppendFormat(" '{0}' ", Me.AddWorkHeader1.WorkItem)
        '        sql.AppendFormat(",'{0}' ", Me.AddWorkHeader1.WorkName)
        '        sql.AppendFormat(",'{0}' ", Me.AddWorkHeader1.Organization)
        '        sql.AppendFormat(",'{0}' ", Me.AddWorkHeader1.WorkPlace)
        '        sql.AppendFormat(",'{0}' ", "1")
        '        sql.AppendFormat(",'{0}' ", Me.AddWorkHeader1.CreateType)
        '        sql.AppendFormat(",{0} ", "getdate()")
        '        sql.AppendFormat(",'{0}' ", Me.LoginID)
        '        dat.AccData(sql)
        '    ElseIf (Me.AddWorkHeader1.DataAccessMode = My.DataAccessMode.Update) Then
        '        sql.AppendFormat("update WorkHeader set")
        '        sql.AppendFormat(" WorkItemID='{0}' ", Me.AddWorkHeader1.WorkItem)
        '        sql.AppendFormat(" ,WorkName='{0}' ", Me.AddWorkHeader1.WorkName)
        '        sql.AppendFormat(" ,OrganizationID='{0}' ", Me.AddWorkHeader1.Organization)
        '        sql.AppendFormat(" ,WorkPlace='{0}' ", Me.AddWorkHeader1.WorkPlace)
        '        sql.AppendFormat(" ,UpdateDate={0} ", "getdate()")
        '        sql.AppendFormat(" ,UpdateBy='{0}' ", Me.LoginID)
        '        sql.AppendFormat(" where WorkHeaderID='{0}' ", Me.AddWorkHeader1.WorkHeaderID)
        '        dat.AccData(sql)
        '    End If
        '    scope.Complete()
        'End Using

        Return True
    End Function

    Private ReadOnly Property LoginID() As String
        Get
            Return Context.User.Identity.Name
        End Get
    End Property

End Class